From df3e1645058367fa959ce103c570324d65f8aed6 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 20 Apr 2012 12:42:59 +0200 Subject: [PATCH] more tests for ContentHandler::getContentText --- includes/ContentHandler.php | 14 ++++++++------ tests/phpunit/includes/ContentHandlerTest.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index c6daeff5ce..e4413b33ac 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -23,19 +23,20 @@ class MWContentSerializationException extends MWException { abstract class ContentHandler { /** - * Conveniance function for getting flat text from a Content object. This shleould only + * Conveniance function for getting flat text from a Content object. This should only * be used in the context of backwards compatibility with code that is not yet able * to handle Content objects! * - * If $content is equal to null or false, this method returns the empty string. + * If $content is null, this method returns the empty string. * - * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getnativeData(). + * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getNativeData(). * * If $content is not a TextContent object, the bahaviour of this method depends on the global $wgContentHandlerTextFallback: - * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown. - * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() + * * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown. + * * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() * is called to get a string form of the content. - * Otherwise, this method returns null. + * * If $wgContentHandlerTextFallback is 'ignore' and $content is not a TextContent object, this method returns null. + * * otherwise, the behaviour is undefined. * * @static * @param Content|null $content @@ -77,6 +78,7 @@ abstract class ContentHandler { * @param null|String $format the format to use for deserialization. If not given, the model's default format is used. * * @return Content a Content object representing $text + * @throw MWException if $model or $format is not supported or if $text can not be unserialized using $format. */ public static function makeContent( $text, Title $title, $modelName = null, $format = null ) { diff --git a/tests/phpunit/includes/ContentHandlerTest.php b/tests/phpunit/includes/ContentHandlerTest.php index 0484116115..0114c43899 100644 --- a/tests/phpunit/includes/ContentHandlerTest.php +++ b/tests/phpunit/includes/ContentHandlerTest.php @@ -30,6 +30,24 @@ class ContentHandlerTest extends MediaWikiTestCase { $this->assertEquals( $expectedModelName, ContentHandler::getDefaultModelFor( $title ) ); } + public function testGetContentText_Null( ) { + global $wgContentHandlerTextFallback; + + $content = null; + + $wgContentHandlerTextFallback = 'fail'; + $text = ContentHandler::getContentText( $content ); + $this->assertEquals( '', $text ); + + $wgContentHandlerTextFallback = 'serialize'; + $text = ContentHandler::getContentText( $content ); + $this->assertEquals( '', $text ); + + $wgContentHandlerTextFallback = 'ignore'; + $text = ContentHandler::getContentText( $content ); + $this->assertEquals( '', $text ); + } + public function testGetContentText_TextContent( ) { global $wgContentHandlerTextFallback; -- 2.20.1